
import React from 'react';
import { Input,Select,Button,Table,Divider } from 'antd';
import { connect } from 'dva';
import styles from './text.less';
const { Search } = Input;
const { Option } = Select;
@connect(({loading,text})=>{
  return{
      ...text,//text是text命名空间的数据，通常是一个对象，...展开对象，返回的对象，这个对象会被 dva 并入到 props 中
      // loading:loading.models.test,
  }
})
  class Text extends React.PureComponent {
	constructor(props) {
		super(props);
		this.state = { selectedRowKeys: [],
        };
    }
     cTitle= (e)=>{
       let param
       if(e=='更新后的新标题'){
         param=e
       }else{
         param=e.target.value
       }
        this.props.dispatch({
        type: 'text/dchangetitle',
        payload:{
          title:param
      }
      }) 

    }
    onSelectChange = selectedRowKeys => {
        console.log('selectedRowKeys changed: ', selectedRowKeys);
        this.setState({ selectedRowKeys });
      };
    columns = [
      {
        title: 'Name',
        dataIndex: 'name',
      },
      {
        title: 'Age',
        dataIndex: 'age',
      },
      {
        title: 'Address',
        dataIndex: 'address',
      },
      {
        title: 'Action',
        dataIndex: 'action',
        render: () => (
            <span>
            <a>edit</a>
            <Divider type="vertical" />
            <a>Delete</a>
            </span>
        ),
      },
    ];
    render(){
        const data = [];
            for (let i = 0; i < 46; i++) {
              data.push({
                key: i,
                name: `Edward King ${i}`,
                age: 32,
                address: `London, Park Lane no. ${i}`,
              });
            } 
       
        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
              console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
            },
            getCheckboxProps: record => ({
              disabled: record.name === 'Disabled User', // Column configuration not to be checked
              name: record.name,
            }),
          };
        return (<div>
                    <div className={styles.searchtop}>
                        <Search
                            placeholder="input search text"
                            onSearch={value => console.log(value)}
                            style={{ width: 200,marginRight:20, }}
                            />
                        <Select defaultValue="Zhejiang"  style={{ marginRight:20, }}>
                            <Option value="Zhejiang">Zhejiang</Option>
                            <Option value="Jiangsu">Jiangsu</Option>
                        </Select>
                        <Button type="primary" style={{marginRight:20, }}>搜索</Button> 
                        <Input onPressEnter={()=>{this.cTitle(event)}}  placeholder="Basic usage" style={{marginRight:20,width:200}}/> 
                        <Button type="primary" onClick={()=>{this.cTitle("更新后的新标题")}}>改变表格标题</Button> 
                    </div>
                    <div className={styles.table}>
                        <h2 style={{padding:'15px', textAlign:"center",backgroundColor:"#ccc",color:"white"}}>{this.props.title}</h2>
                        <Table rowSelection={rowSelection} columns={this.columns} dataSource={data} />
                    </div>


                </div>)
    }
}
export default Text 